package com.songtai.service.impl;

import java.util.List;

import com.songtai.dao.PublicObjDao;
import com.songtai.po.PublicObj;
import com.songtai.util.PageBean;

/**
 * 通用文字信息
 * 
 * @author lx
 * 
 */
public class PublicObjServiceImpl implements com.songtai.service.PublicObjService {

	private PublicObjDao publicObjDao;

	@Override
	public void addObj(PublicObj publicObj) {
		publicObjDao.createObject(publicObj);
	}

	@Override
	public void delObjs(String ids,String nid) {
		String temp = ids.substring(0, ids.length() - 1);
		String[] temp2 = temp.split(",");
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < temp2.length; i++) {
			sb.append("'" + temp2[i] + "',");
		}
		temp = sb.toString();
		temp = temp.substring(0, temp.length() - 1);
		String hql = "delete from PublicObj where id in(" + temp + ") and nid ="+nid;
		publicObjDao.deleteEntities(hql);
	}

	/**
	 * 前后台根据nid获取相应文字信息
	 */
	public List<PublicObj> getObjsByNid(String nid) {
		return publicObjDao.getObjsByNid(nid);
	}
	
	/**
	 * 根据nid获取单个
	 * @param nid
	 * @return
	 */
	public PublicObj getObjByNid(String nid) {
		return publicObjDao.getPublicObj(nid);
	}
	
	/**
	 * 删除单个信息
	 * 
	 * @param id
	 */
	public void delPublicObjById(PublicObj obj) {
		publicObjDao.deleteObject(obj);
	}
	
	
	@Override
	public PublicObj getObj(String id) {
		return publicObjDao.readObjectById(id);
	}

	@Override
	public PageBean getObjs(PageBean pageBean) {
		return publicObjDao.findPageEntities(pageBean);
	}

	@Override
	public void updateObj(PublicObj publicObj) {
		publicObjDao.updateObject(publicObj);
	}

	public void setPublicObjDao(PublicObjDao publicObjDao) {
		this.publicObjDao = publicObjDao;
	}

}
